/*
* 变量捕获
* */

public class Demo5 {
    public static Boolean isQuit = false;

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            while(!isQuit){
                System.out.println("线程正在运行");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程运行结束");
        });

        t.start();
        Thread.sleep(5000);
        isQuit = true;
        System.out.println("设置isQuit为true");
    }
}
/*
* 如果吧isQuit这个成员变量改成main方法中的局部变量,是否可行?
* */
